package org.nterlearning.datamodel.catalog.model.impl;

import com.liferay.portal.kernel.bean.AutoEscapeBeanHandler;
import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.portal.kernel.util.ProxyUtil;
import com.liferay.portal.kernel.util.StringBundler;
import com.liferay.portal.kernel.util.StringPool;
import com.liferay.portal.model.CacheModel;
import com.liferay.portal.model.impl.BaseModelImpl;
import com.liferay.portal.service.ServiceContext;

import com.liferay.portlet.expando.model.ExpandoBridge;
import com.liferay.portlet.expando.util.ExpandoBridgeFactoryUtil;

import org.nterlearning.datamodel.catalog.model.ExternalLink;
import org.nterlearning.datamodel.catalog.model.ExternalLinkModel;

import java.io.Serializable;

import java.sql.Types;

/**
 * The base model implementation for the ExternalLink service. Represents a row in the &quot;CATALOG_ExternalLink&quot; database table, with each column mapped to a property of this class.
 *
 * <p>
 * This implementation and its corresponding interface {@link org.nterlearning.datamodel.catalog.model.ExternalLinkModel} exist only as a container for the default property accessors generated by ServiceBuilder. Helper methods and all application logic should be put in {@link ExternalLinkImpl}.
 * </p>
 *
 * @author Brian Wing Shun Chan
 * @see ExternalLinkImpl
 * @see org.nterlearning.datamodel.catalog.model.ExternalLink
 * @see org.nterlearning.datamodel.catalog.model.ExternalLinkModel
 * @generated
 */
public class ExternalLinkModelImpl extends BaseModelImpl<ExternalLink>
    implements ExternalLinkModel {
    /*
     * NOTE FOR DEVELOPERS:
     *
     * Never modify or reference this class directly. All methods that expect a external link model instance should use the {@link org.nterlearning.datamodel.catalog.model.ExternalLink} interface instead.
     */
    public static final String TABLE_NAME = "CATALOG_ExternalLink";
    public static final Object[][] TABLE_COLUMNS = {
            { "linkId", Types.BIGINT },
            { "courseId", Types.BIGINT },
            { "componentId", Types.BIGINT },
            { "linkType", Types.VARCHAR },
            { "linkUrl", Types.VARCHAR }
        };
    public static final String TABLE_SQL_CREATE = "create table CATALOG_ExternalLink (linkId LONG not null primary key,courseId LONG,componentId LONG,linkType VARCHAR(255) null,linkUrl VARCHAR(3999) null)";
    public static final String TABLE_SQL_DROP = "drop table CATALOG_ExternalLink";
    public static final String DATA_SOURCE = "liferayDataSource";
    public static final String SESSION_FACTORY = "liferaySessionFactory";
    public static final String TX_MANAGER = "liferayTransactionManager";
    public static final boolean ENTITY_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.util.service.ServiceProps.get(
                "value.object.entity.cache.enabled.org.nterlearning.datamodel.catalog.model.ExternalLink"),
            true);
    public static final boolean FINDER_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.util.service.ServiceProps.get(
                "value.object.finder.cache.enabled.org.nterlearning.datamodel.catalog.model.ExternalLink"),
            true);
    public static final boolean COLUMN_BITMASK_ENABLED = GetterUtil.getBoolean(com.liferay.util.service.ServiceProps.get(
                "value.object.column.bitmask.enabled.org.nterlearning.datamodel.catalog.model.ExternalLink"),
            true);
    public static long COMPONENTID_COLUMN_BITMASK = 1L;
    public static long COURSEID_COLUMN_BITMASK = 2L;
    public static long LINKTYPE_COLUMN_BITMASK = 4L;
    public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(com.liferay.util.service.ServiceProps.get(
                "lock.expiration.time.org.nterlearning.datamodel.catalog.model.ExternalLink"));
    private static ClassLoader _classLoader = ExternalLink.class.getClassLoader();
    private static Class<?>[] _escapedModelProxyInterfaces = new Class[] {
            ExternalLink.class
        };
    private long _linkId;
    private long _courseId;
    private long _originalCourseId;
    private boolean _setOriginalCourseId;
    private long _componentId;
    private long _originalComponentId;
    private boolean _setOriginalComponentId;
    private String _linkType;
    private String _originalLinkType;
    private String _linkUrl;
    private transient ExpandoBridge _expandoBridge;
    private long _columnBitmask;
    private ExternalLink _escapedModelProxy;

    public ExternalLinkModelImpl() {
    }

    public long getPrimaryKey() {
        return _linkId;
    }

    public void setPrimaryKey(long primaryKey) {
        setLinkId(primaryKey);
    }

    public Serializable getPrimaryKeyObj() {
        return new Long(_linkId);
    }

    public void setPrimaryKeyObj(Serializable primaryKeyObj) {
        setPrimaryKey(((Long) primaryKeyObj).longValue());
    }

    public Class<?> getModelClass() {
        return ExternalLink.class;
    }

    public String getModelClassName() {
        return ExternalLink.class.getName();
    }

    public long getLinkId() {
        return _linkId;
    }

    public void setLinkId(long linkId) {
        _linkId = linkId;
    }

    public long getCourseId() {
        return _courseId;
    }

    public void setCourseId(long courseId) {
        _columnBitmask |= COURSEID_COLUMN_BITMASK;

        if (!_setOriginalCourseId) {
            _setOriginalCourseId = true;

            _originalCourseId = _courseId;
        }

        _courseId = courseId;
    }

    public long getOriginalCourseId() {
        return _originalCourseId;
    }

    public long getComponentId() {
        return _componentId;
    }

    public void setComponentId(long componentId) {
        _columnBitmask |= COMPONENTID_COLUMN_BITMASK;

        if (!_setOriginalComponentId) {
            _setOriginalComponentId = true;

            _originalComponentId = _componentId;
        }

        _componentId = componentId;
    }

    public long getOriginalComponentId() {
        return _originalComponentId;
    }

    public String getLinkType() {
        if (_linkType == null) {
            return StringPool.BLANK;
        } else {
            return _linkType;
        }
    }

    public void setLinkType(String linkType) {
        _columnBitmask |= LINKTYPE_COLUMN_BITMASK;

        if (_originalLinkType == null) {
            _originalLinkType = _linkType;
        }

        _linkType = linkType;
    }

    public String getOriginalLinkType() {
        return GetterUtil.getString(_originalLinkType);
    }

    public String getLinkUrl() {
        if (_linkUrl == null) {
            return StringPool.BLANK;
        } else {
            return _linkUrl;
        }
    }

    public void setLinkUrl(String linkUrl) {
        _linkUrl = linkUrl;
    }

    public long getColumnBitmask() {
        return _columnBitmask;
    }

    @Override
    public ExternalLink toEscapedModel() {
        if (_escapedModelProxy == null) {
            _escapedModelProxy = (ExternalLink) ProxyUtil.newProxyInstance(_classLoader,
                    _escapedModelProxyInterfaces,
                    new AutoEscapeBeanHandler(this));
        }

        return _escapedModelProxy;
    }

    @Override
    public ExpandoBridge getExpandoBridge() {
        if (_expandoBridge == null) {
            _expandoBridge = ExpandoBridgeFactoryUtil.getExpandoBridge(0,
                    ExternalLink.class.getName(), getPrimaryKey());
        }

        return _expandoBridge;
    }

    @Override
    public void setExpandoBridgeAttributes(ServiceContext serviceContext) {
        getExpandoBridge().setAttributes(serviceContext);
    }

    @Override
    public Object clone() {
        ExternalLinkImpl externalLinkImpl = new ExternalLinkImpl();

        externalLinkImpl.setLinkId(getLinkId());
        externalLinkImpl.setCourseId(getCourseId());
        externalLinkImpl.setComponentId(getComponentId());
        externalLinkImpl.setLinkType(getLinkType());
        externalLinkImpl.setLinkUrl(getLinkUrl());

        externalLinkImpl.resetOriginalValues();

        return externalLinkImpl;
    }

    public int compareTo(ExternalLink externalLink) {
        long primaryKey = externalLink.getPrimaryKey();

        if (getPrimaryKey() < primaryKey) {
            return -1;
        } else if (getPrimaryKey() > primaryKey) {
            return 1;
        } else {
            return 0;
        }
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }

        ExternalLink externalLink = null;

        try {
            externalLink = (ExternalLink) obj;
        } catch (ClassCastException cce) {
            return false;
        }

        long primaryKey = externalLink.getPrimaryKey();

        if (getPrimaryKey() == primaryKey) {
            return true;
        } else {
            return false;
        }
    }

    @Override
    public int hashCode() {
        return (int) getPrimaryKey();
    }

    @Override
    public void resetOriginalValues() {
        ExternalLinkModelImpl externalLinkModelImpl = this;

        externalLinkModelImpl._originalCourseId = externalLinkModelImpl._courseId;

        externalLinkModelImpl._setOriginalCourseId = false;

        externalLinkModelImpl._originalComponentId = externalLinkModelImpl._componentId;

        externalLinkModelImpl._setOriginalComponentId = false;

        externalLinkModelImpl._originalLinkType = externalLinkModelImpl._linkType;

        externalLinkModelImpl._columnBitmask = 0;
    }

    @Override
    public CacheModel<ExternalLink> toCacheModel() {
        ExternalLinkCacheModel externalLinkCacheModel = new ExternalLinkCacheModel();

        externalLinkCacheModel.linkId = getLinkId();

        externalLinkCacheModel.courseId = getCourseId();

        externalLinkCacheModel.componentId = getComponentId();

        externalLinkCacheModel.linkType = getLinkType();

        String linkType = externalLinkCacheModel.linkType;

        if ((linkType != null) && (linkType.length() == 0)) {
            externalLinkCacheModel.linkType = null;
        }

        externalLinkCacheModel.linkUrl = getLinkUrl();

        String linkUrl = externalLinkCacheModel.linkUrl;

        if ((linkUrl != null) && (linkUrl.length() == 0)) {
            externalLinkCacheModel.linkUrl = null;
        }

        return externalLinkCacheModel;
    }

    @Override
    public String toString() {
        StringBundler sb = new StringBundler(11);

        sb.append("{linkId=");
        sb.append(getLinkId());
        sb.append(", courseId=");
        sb.append(getCourseId());
        sb.append(", componentId=");
        sb.append(getComponentId());
        sb.append(", linkType=");
        sb.append(getLinkType());
        sb.append(", linkUrl=");
        sb.append(getLinkUrl());
        sb.append("}");

        return sb.toString();
    }

    public String toXmlString() {
        StringBundler sb = new StringBundler(19);

        sb.append("<model><model-name>");
        sb.append("org.nterlearning.datamodel.catalog.model.ExternalLink");
        sb.append("</model-name>");

        sb.append(
            "<column><column-name>linkId</column-name><column-value><![CDATA[");
        sb.append(getLinkId());
        sb.append("]]></column-value></column>");
        sb.append(
            "<column><column-name>courseId</column-name><column-value><![CDATA[");
        sb.append(getCourseId());
        sb.append("]]></column-value></column>");
        sb.append(
            "<column><column-name>componentId</column-name><column-value><![CDATA[");
        sb.append(getComponentId());
        sb.append("]]></column-value></column>");
        sb.append(
            "<column><column-name>linkType</column-name><column-value><![CDATA[");
        sb.append(getLinkType());
        sb.append("]]></column-value></column>");
        sb.append(
            "<column><column-name>linkUrl</column-name><column-value><![CDATA[");
        sb.append(getLinkUrl());
        sb.append("]]></column-value></column>");

        sb.append("</model>");

        return sb.toString();
    }
}
